package com.rambler.extension.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rambler.common.response.CommonResponse;
import com.rambler.extension.converters.ExtSearchEngineConverter;
import com.rambler.extension.dto.ExtSearchEngineDTO;
import com.rambler.extension.entity.ExtSearchEngine;
import com.rambler.extension.service.ExtSearchEngineService;
import com.rambler.extension.vo.ExtUserEngineVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 搜索引擎配置接口
 * 提供搜索引擎的增删改查及用户绑定查询
 *
 * @author suhao
 */
@RestController
@Tag(name = "搜索引擎接口", description = "提供搜索引擎的创建、查询、更新、删除及用户绑定相关功能")
public class ExtSearchEngineController {

    @Resource
    private ExtSearchEngineService engineService;

    @Resource
    private ExtSearchEngineConverter engineConverter;

    /**
     * 查询指定用户绑定的全部启用搜索引擎
     */
    @GetMapping("/engines")
    @Operation(summary = "查询用户绑定的搜索引擎", description = "根据用户ID查询该用户绑定的所有启用搜索引擎")
    public CommonResponse<List<ExtUserEngineVO>> getUserEngines(
            @Parameter(description = "用户ID", required = true)
            @RequestParam("userId") String userId) {
        if (userId == null || userId.isEmpty()) {
            return CommonResponse.failure("用户ID不能为空");
        }
        return engineService.getUserEngines(userId);
    }

//    /**
//     * 创建新搜索引擎配置
//     */
//    @PostMapping
//    @Operation(summary = "创建搜索引擎", description = "根据请求体信息新增一个搜索引擎配置")
//    public CommonResponse<ExtUserEngineVO> createEngine(
//            @Parameter(description = "搜索引擎创建请求体", required = true)
//            @RequestBody ExtSearchEngineDTO searchEngineDTO) {
//        return engineService.createEngine(searchEngineDTO);
//    }
//
//    /**
//     * 更新搜索引擎配置
//     */
//    @PutMapping
//    @Operation(summary = "更新搜索引擎", description = "根据请求体信息更新已有搜索引擎配置")
//    public CommonResponse<ExtUserEngineVO> updateEngine(
//            @Parameter(description = "搜索引擎更新请求体", required = true)
//            @RequestBody ExtSearchEngineDTO searchEngineDTO) {
//        return engineService.updateEngine(searchEngineDTO);
//    }

    /**
     * 删除指定搜索引擎配置
     */
    @DeleteMapping("/{userId}/{engineId}")
    @Operation(summary = "删除搜索引擎", description = "根据搜索引擎ID删除对应搜索引擎配置")
    public CommonResponse<Void> deleteEngine(
            @Parameter(description = "用户ID", required = true)
            @PathVariable("userId") String userId,
            @Parameter(description = "搜索引擎ID", required = true)
            @PathVariable("engineId") String engineId
    ) {
        if (userId == null || engineId == null) {
            return CommonResponse.failure("搜索引擎ID或者用户id不能为空");
        }
        return engineService.deleteEngine(userId, engineId);
    }
}
